<template>
  <div style="">
    <Header :left="true" leftText="返回" title="调机申请"> </Header>
    <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
      left-icon="description">调机通知单</NoticeBar>

    <van-form :style="autoHeight" @submit="onSubmit">
      <van-field required readonly clickable class="formstyle" name="datetimePicker" :value="form.ProductionDate"
        label="生产日期" placeholder="点击选择时间" @click="showProductionDate = true" />
      <van-popup v-model="showProductionDate" position="bottom">
        <van-datetime-picker type="date" @confirm="onConfirmProductionDate" @cancel="showProductionDate = false"
          :min-date="minDate" :max-date="maxDate" :value="currentdate" />
      </van-popup>

      <van-field class="formstyle" required v-model="form.POrderID" name="生产订单" label="生产订单" placeholder="输入生产订单"
        @click.stop="getcurrentorder" />
      <van-field required readonly class="formstyle" :value="form.MaterialName" name="物料名称" label="物料名称"
        placeholder="输入物料名称" />
      <van-field required class="formstyle" readonly :value="form.MaterialID" name="物料号" label="物料号"
        placeholder="输入物料号" />
      <!-- <van-field required class="formstyle" readonly :value="item.Id" name="外观检验记录" label="外观检验记录"
        placeholder="输入外观检验记录" /> -->
      <van-field required readonly clickable class="formstyle" name="datetimePicker" :value="form.ProDatetimeFrom"
        label="生产时间从" placeholder="点击选择时间" @click="showProDatetimeFrom = true" />
      <van-popup v-model="showProDatetimeFrom" position="bottom">
        <van-datetime-picker type="datetime" @confirm="onConfirmProDatetimeFrom" @cancel="showProDatetimeFrom = false"
          :min-date="minDate" :max-date="maxDate" :value="currentdate" />
      </van-popup>
      <van-field required readonly clickable class="formstyle" name="datetimePicker" :value="form.ProDatetimeTo"
        label="生产时间至" placeholder="点击选择时间" @click="showProDatetimeTo = true" />
      <van-popup v-model="showProDatetimeTo" position="bottom">
        <van-datetime-picker type="datetime" @confirm="onConfirmProDatetimeTo" @cancel="showProDatetimeTo = false"
          :min-date="minDate" :max-date="maxDate" :value="currentdate" />
      </van-popup>

      <van-field readonly class="formstyle" name="picker" v-model="form.QProblemID" label="缺陷类型" type="textarea" rows="4"
        @click="showQProblemID = true" />
      <van-field class="formstyle" v-model="form.Reasons" name="需注明的缺陷描述" label="需注明的缺陷描述" placeholder="需注明的缺陷描述"
        type="textarea" rows="4" maxlength="1000" />


      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">基本信息</NoticeBar>
      <van-field class="formstyle" v-model="form.NoticeMemo" name="通知单描述" label="通知单描述" placeholder="输入通知单描述" />

      <van-field required readonly class="formstyle" name="picker" :value="valuepShiftName" label="班次"
        placeholder="点击选择班次" @click="showPickerpShiftID = true" />
      <van-popup v-model="showPickerpShiftID" position="bottom">
        <van-picker show-toolbar :columns="columnsshift" @confirm="onConfirmpShiftID"
          @cancel="showPickerpShiftID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.pshiftname }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field class="formstyle" readonly v-model="form.ProductionBatch" name="生产批次" label="生产批次"
        placeholder="输入生产批次" />
      <!-- <van-field class="formstyle" :value="form.pOrderID" name="物料规格" label="物料规格" placeholder="输入物料规格" /> -->
      <van-field required readonly class="formstyle" name="picker" :value="valuepMachineEquipment" label="设备代码"
        placeholder="点击选择设备代码" @click="showPickerpMachineEquipmentID = true" />
      <van-popup v-model="showPickerpMachineEquipmentID" position="bottom">
        <van-picker show-toolbar :columns="columnsMachineEquipment" @confirm="onConfirmpMachineEquipmentID"
          @cancel="showPickerpMachineEquipmentID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.pMachineName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field class="formstyle" required v-model="form.SampleAmount" name="抽样数量" label="抽样数量" placeholder="输入抽样数量" />
      <van-field class="formstyle" required v-model="form.AbnormalAmount" name="异常数量" label="异常数量" placeholder="输入异常数量" />
      <van-field class="formstyle" v-model="form.ProductionColor" name="产品颜色" label="产品颜色" placeholder="输入产品颜色" />
      <van-field :readonly="true" class="formstyle" v-model="user.userName" name="调机单申请QC" label="调机单申请QC"
        placeholder="输入调机单申请QC" />
      <van-field :readonly="true" class="formstyle" v-model="nowDate" name="创建时间" label="创建时间" placeholder="输入创建时间" />
      <van-field required readonly class="formstyle" style="font-weight: bold" name="picker"
        :value="form.AppearanceCheckRecord1" label="外观检验记录" placeholder="选择外观检验记录" />

      <van-popup v-model="showPickerWG" position="bottom">
        <van-picker show-toolbar :columns="WGlist2" @confirm="onConfirmWG" @cancel="showPickerWG = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.showP }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKeyWG" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <van-field required readonly class="formstyle" style="font-weight: bold" name="picker"
        :value="form.LaboratoryCheckRecord1" label="实验室检验记录" placeholder="选择实验室检验记录" @click="showPickerSYS = true" />
      <van-popup v-model="showPickerSYS" position="bottom">
        <van-picker show-toolbar :columns="SYSlist2" @confirm="onConfirmSYS" @cancel="showPickerSYS = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.showP }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKeySYS" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <div style="margin: 16px"
        v-if="form.LaboratoryCheckRecord1 != 0 && form.LaboratoryCheckRecord1 != '' && form.LaboratoryCheckRecord1 != null">
        <van-button color="#23C6C8" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
      </div>

      <div style="margin: 16px"
        v-if="form.AppearanceCheckRecord1 != 0 && form.AppearanceCheckRecord1 != '' && form.AppearanceCheckRecord1 != null">
        <van-button color="" round block type="info" @click="getRecord(form.AppearanceCheckRecord1)"
          style="">查看外观检验不合格记录</van-button>
      </div>
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">质量要求</NoticeBar>
      <div style="margin: 16px">
        <van-checkbox-group v-model="result">
          <van-checkbox name="Require1">及时调机整改</van-checkbox>
          <van-checkbox name="Require2">停机调整</van-checkbox>
          <van-checkbox name="Require3">产品要求返工，发出返工通知单</van-checkbox>
          <van-checkbox name="Require4">在线自检挑出</van-checkbox>
        </van-checkbox-group>

        <van-field required readonly class="formstyle" name="picker" :value="EmployeeName1" label="品管领班审核"
          placeholder="点击选择品管领班" @click="showPickerEmployee = true" />
        <van-popup v-model="showPickerEmployee" position="bottom">
          <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
            @cancel="showPickerEmployee = false">
            <template #option="option">
              <div style="display: flex; flex-direction: column; align-items: center;">
                <div>{{ option.EmployeeName }}</div>
              </div>
            </template>
          </van-picker>
        </van-popup>
        <van-field class="formstyle" v-model="form.AbnormalDescription" name="质量要求" label="质量要求" placeholder="输入质量要求" />
      </div>
      <!-- <div style="margin: 16px">
        <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
      </div> -->

      <van-row class="button" gutter="2">
        <van-col span="12">
          <van-button color="#138087" round block type="primary" native-type="submit" @click="submitsure1">跳过</van-button>
        </van-col>
        <van-col span="12">
          <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
        </van-col>
      </van-row>


    </van-form>
  </div>
</template>

<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient } from "@/libs/apisie";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "qCcheckApplicationNew",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      columnsEmployeeND: [],
      showPickerEmployee: false,
      item: {},
      item2: {},
      query: {
        QProblemName: "",
      },
      columnsEmployee: [],
      result: [],
      columnsshift: [],
      columnsQProblem: [],
      columnsMachineEquipment: [],
      minDate: new Date(2023, 1, 1),
      maxDate: new Date(2025, 10, 1),
      currentdate: new Date(),
      nowDate: null,
      showProductionDate: false,
      showProDatetimeFrom: false,
      showProDatetimeTo: false,
      showPickerpShiftID: false,
      showQProblemID: false,
      showPickerpMachineEquipmentID: false,
      //外观
      showPickerWG: false,
      WGlist: [],
      WGlist2: [],
      searchKeyWG: "",
      EmployeeID: "",
      //实验室检验记录
      showPickerSYS: false,
      SYSlist: [],
      SYSlist2: [],
      searchKeySYS: "",

      user: [],
      form: {
        ProductionDate: "",
        POrderID: "",
        MaterialName: "",
        MaterialID: "",
        ProDatetimeFrom: "",
        ProDatetimeTo: "",
        QProblemID: "",
        FactoryID: "",
        PShiftID: "",
        Reasons: "",
        ProductionBatch: "",
        MachineID: "",
        SampleAmount: "",
        AbnormalAmount: "",
        ProductionColor: "",
        AbnormalDescription: "",
        NoticeMemo: "",
        Require1: false,
        Require2: false,
        Require3: false,
        Require4: false,
      },
    };
  },
  created: function () {
    this.user = JSON.parse(storage.get("user"));
    this.user.userId = this.user.userName;
    this.getNowTimeToSecond(); //进入页面调用该方法获取当前时间
    //获取班次信息
    this.getshift();
    this.getQualityProblems();
    this.getWGList();
    this.getSYSList();
    this.getEmployeeID();
    // if (typeof api.pageParam.item != "undefined") {
    // alert(JSON.stringify(api.pageParam.item));
    this.form.ProductionDate = api.pageParam.item.ProductionDate;
    this.form.POrderID = api.pageParam.item.POrderID;
    this.form.MaterialName = api.pageParam.item.MaterialName;
    this.form.MaterialID = api.pageParam.item.MaterialID;
    this.item = api.pageParam.item;
    this.form.NoticeMemo = api.pageParam.item.POrderID + "-" + api.pageParam.item.BatchID + "-" + api.pageParam.item.planworkdatetime
    this.form.ProductionBatch = this.item.BatchID
    this.form.AppearanceCheckRecord1 = this.item.Id
    this.form.Reasons = this.item.Memo
    this.form.SampleAmount = this.item.sampleAmount
    this.form.AbnormalAmount = parseInt(this.item.samplePlan1Value)+parseInt(this.item.samplePlan2Value)
    this.valuepMachineEquipment = this.item.PLineID;
    this.form.MachineID = this.item.PLineID;
    // this.form.Reasons=this.item.Reasons
    // }

    if (typeof api.pageParam.item2 != "undefined") {
      this.item2 = api.pageParam.item2;
      // alert(JSON.stringify(this.item2))
    }

    // alert(JSON.stringify(api.pageParam.item3))


    if (typeof api.pageParam.item3 != "undefined") {

      this.form.QProblemID = api.pageParam.item3.join(";");
    }


    //alert(this.item.valueplineid);
    this.getMachineEquipment();
  },
  mounted() { },
  watch: {

    'searchKeyWG': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.WGlist2 = this.WGlist.filter(item => item.showP.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,

    },

    'searchKey1': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.columnsEmployeeND = this.columnsEmployee.filter(item => item.EmployeeName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },
    'searchKeySYS': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.SYSlist2 = this.SYSlist.filter(item => item.showP.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,

    }
  },

  destroyed() {
    clearInterval(this.nowtimer);
    this.nowDate = null;
  },

  methods: {
    async getEmployeeID() {
      this.columnsEmployee = []
      // alert(_httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID)
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW11GW32GW33",
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
          temp.forEach(item => {
            _this.columnsEmployee.push(item);
            _this.columnsEmployeeND.push(item);
          })
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmEmployee(value, index) {
      this.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
      this.EmployeeName1 = this.columnsEmployeeND[index].EmployeeName;
      this.showPickerEmployee = false;
    },
    //外观
    async getWGList() {
      //QualityAppearanceCheck/GetPageListJson
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/QualityAppearanceCheck/GetList"
        );
        if (res.HttpCode === "200") {

          let teamMap = res.Data.map((item) => ({
            Id: item.Id,
            showP: item.Id + " " + item.MaterialName,
          }));
          _this.WGlist = teamMap;
          _this.WGlist2 = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }

    },
    onConfirmWG(value, index) {

      this.form.AppearanceCheckRecord1 = this.WGlist2[index].Id;
      this.form.AppearanceCheckRecordName1 = this.WGlist2[index].showP;
      this.showPickerWG = false;
    },

    getRecord(id) {


      api.openWin({
        name: 'qCcheckReview',
        url: './quality-qCcheckReview.html',
        pageParam: {
          id: id
        }
      });

    },

    //实验室
    async getSYSList() {
      //QualityAppearanceCheck/GetPageListJson
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/QualityCheckRecord/GetList"
        );
        if (res.HttpCode === "200") {

          let teamMap = res.Data.map((item) => ({
            Id: item.Id,
            showP: item.Id + " " + item.SheetName,
          }));
          _this.SYSlist = teamMap;
          _this.SYSlist2 = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }

    },
    onConfirmSYS(value, index) {

      this.form.LaboratoryCheckRecord1 = this.SYSlist2[index].Id;
      this.form.LaboratoryCheckRecordName1 = this.SYSlist2[index].showP;
      this.showPickerSYS = false;
    },

    async checkSYS() {
      // let id=this.form.LaboratoryCheckRecord1

      // if(id==""||id==null || id==undefined){
      //   Toast.clear()
      //   Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
      //   return
      // }


      // //QualityCheckRecord/GetQualityCheckDisqualifiedMsg?CheckRecordID=609416630832730112

      // try {
      //   let res = await _httpClient.get(
      //     _httpClient.getApiPrefix() +
      //     "/QualityCheckRecord/GetQualityCheckDisqualifiedMsg?CheckRecordID="+id
      //   );
      //   if (res.HttpCode === "200") {
      //     alert(res.Data)
      //   }
      // } catch (e) {
      //   Toast.fail(JSON.stringify(e));
      // }

      let id = this.form.LaboratoryCheckRecord1


      if (id == "" || id == null || id == undefined) {
        Toast.clear()
        Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
        return
      }

      api.openWin({
        name: 'viewlaboratorytest',
        url: './equipmentsj-viewlaboratorytest.html',
        pageParam: {
          id: id
        }
      });
    },
    getNowTimeplus() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    handleSearchNations() { },
    //获取⽣产线正在⽣产订单
    async getcurrentorder() {
      var _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/ProductionOrder/GetList?POrderID=" +
          _this.form.POrderID
        );
        if (res.HttpCode === "200" && res.Total == 1) {
          Toast.clear();
          _this.form.POrderID = res.Data[0].POrderID;
          _this.form.MaterialID = res.Data[0].MaterialID;
          _this.form.MaterialName = res.Data[0].MaterialName;
          _this.form.FactoryID = res.Data[0].FactoryID;
        } else {
          (_this.form.MaterialID = ""), (_this.form.MaterialName = "");
          _this.form.FactoryID = "";
          Toast.fail("请将订单号输入在精准一些");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async submitsure() {
      var _this = this;

      if (_this.EmployeeID == "") {
        Toast.fail("请选择品管领班");
        return;
      }

      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "请稍等...",
      });
      Toast.fail(JSON.stringify(_this.result));
      _this.result.forEach((item) => {
        if (item == "Require1") {
          _this.form.Require1 = true;
        }
        if (item == "Require2") {
          _this.form.Require2 = true;
        }
        if (item == "Require3") {
          _this.form.Require3 = true;
        }
        if (item == "Require4") {
          _this.form.Require4 = true;
        }
      });
      try {
        alert(_this.form.QProblemID)
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/QualityAbnormalNotice/SaveEntity",
          {
            body: {
              ProductionDate: _this.form.ProductionDate,
              POrderID: _this.form.POrderID,
              MaterialName: _this.form.MaterialName,
              Reasons: _this.form.Reasons,
              MaterialID: _this.form.MaterialID,
              ProDatetimeFrom: _this.form.ProDatetimeFrom,
              ProDatetimeTo: _this.form.ProDatetimeTo,
              QProblemID: _this.form.QProblemID,
              FactoryID: "TC00",
              ResourceFrom: "APP",
              PShiftID: _this.form.PShiftID,
              ProductionBatch: _this.form.ProductionBatch,
              MachineID: _this.form.MachineID,
              SampleAmount: _this.form.SampleAmount,
              AbnormalAmount: _this.form.AbnormalAmount,
              ProductionColor: _this.form.ProductionColor,
              NoticeMemo: _this.form.NoticeMemo,
              Creator: _this.user.userName,
              CreateDatetime: new Date(),
              Require4: _this.form.Require4,
              Require3: _this.form.Require3,
              Require2: _this.form.Require2,
              Require1: _this.form.Require1,
              AbnormalDescription: _this.form.AbnormalDescription,
              LaboratoryCheckRecord1: _this.form.LaboratoryCheckRecord1,
              AppearanceCheckRecord1: _this.form.AppearanceCheckRecord1,
              QCLeaderUserID: _this.EmployeeID
            },
          }
        );
        if (res.Message != null) {
          //message不为空,有报错信息，打卡失败 暂时这样判断
          Toast.clear();
          Toast.fail("保存失败,请核对信息！");
        } else {
          //打卡成功
          Toast.clear();
          Toast.success("保存成功！");
          _this.sendmessage();
          // setTimeout(function () {
          //   _this.$ac.closeWin();
          // }, 2000);

        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async sendmessage() {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTimeplus();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = _this.form.MachineID;
      let machineID = "";
      let pShiftID = "";
      let teamID = "";
      let pOrderID = "";
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTimeplus();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "ABN01";
      eventID = "ABN01";
      eventDescription = "订单:" + _this.form.POrderID + "的调机单已经被品管员创建，请品管领班进行调机单的后续审核！";
      messageContent = "生产订单" + _this.form.POrderID + "在机台:" + _this.form.MachineID + "上生产时发生质量异常，质量原因是:" + _this.form.AbnormalDescription + "已创建调机申请单.请品管领班进行调机单后续审批！";


      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);
          api.openWin({
            name: "quality-qCcheckApplication",
            url: "./quality-qCcheckApplication.html",
            reload: true,
            pageParam: {
              item: _this.item2,
              // item2: _this.item2,
            },
          });
        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async submitsure1() {
      var _this = this;

      Toast.fail(JSON.stringify(_this.result));
      _this.result.forEach((item) => {
        if (item == "Require1") {
          _this.form.Require1 = true;
        }
        if (item == "Require2") {
          _this.form.Require2 = true;
        }
        if (item == "Require3") {
          _this.form.Require3 = true;
        }
        if (item == "Require4") {
          _this.form.Require4 = true;
        }
      });
      Toast.success("跳过操作");
      setTimeout(function () {
        _this.$ac.closeWin();
      }, 2000);
      api.openWin({
        name: "quality-qCcheckApplication",
        url: "./quality-qCcheckApplication.html",
        reload: true,
        pageParam: {
          item: _this.item2,
          // item2: _this.item2,
        },
      });

    },
    //获取班次信息
    async getshift() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/ProductionShift/GetList?FactoryID=" +
          _this.FactoryID
        );
        if (res.HttpCode === "200") {
          for (let index = 0; index < res.Data.length; index++) {
            if (res.Data[index].Actived == false) {
              delete res.Data[index];
            }
          }
          let shiftMap = res.Data.map((item) => ({
            pshiftname: item.PShiftName + " " + item.BeginTime,
            pShiftID: item.PShiftID,
            BeginTime: item.BeginTime,
          }));
          _this.columnsshift = shiftMap;
          _this.valuepShiftName = _this.columnsshift[0].pshiftname;
          _this.form.PShiftID = _this.columnsshift[0].pShiftID;
          _this.BeginTime = _this.columnsshift[0].BeginTime;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    onConfirmpShiftID(value, index) {
      this.valuepShiftName = this.columnsshift[index].pshiftname;
      this.form.PShiftID = this.columnsshift[index].pShiftID;
      this.BeginTime = this.columnsshift[index].BeginTime;
      this.showPickerpShiftID = false;
    },

    //获取缺陷原因
    async getQualityProblems() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/QualityProblems/GetList?QProblemName=" +
          _this.query.QProblemName
        );
        if (res.HttpCode === "200") {
          let qualityProblemsMap = res.Data.map((item) => ({
            QProblemID: item.QProblemID,
            QProblemName: item.QProblemName,
          }));
          _this.columnsQProblem = qualityProblemsMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    onConfirmpQProblemID(value, index) {
      this.valueQProblemName = this.columnsQProblem[index].QProblemName;
      this.form.QProblemID = this.columnsQProblem[index].QProblemID;
      this.showQProblemID = false;
    },

    //获取设备信息
    async getMachineEquipment() {
      //alert(_this.item.valueplineid);
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/MachineEquipment/GetList"
        );
        if (res.HttpCode === "200") {
          let machineEquipmenttMap = res.Data.map((item) => ({
            pMachineName: item.MachineName,
            pMachineID: item.MachineID,
          }));
          _this.columnsMachineEquipment = machineEquipmenttMap;
          machineEquipmenttMap.forEach(element => {
            if (element.pMachineID == _this.item.valueplineid) {
              this.valuepMachineEquipment = element.pMachineName;
              this.form.MachineID = element.pMachineID;
            }
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    onConfirmpMachineEquipmentID(value, index) {
      this.valuepMachineEquipment =
        this.columnsMachineEquipment[index].pMachineName;
      this.form.MachineID = this.columnsMachineEquipment[index].pMachineID;
      this.showPickerpMachineEquipmentID = false;
    },

    onConfirmProductionDate(time) {
      this.tempTime = time;
      //date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); // 时区补偿
      this.form.ProductionDate = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()}`;
      this.showProductionDate = false;
    },
    onConfirmProDatetimeFrom(time) {
      this.tempTime = time;
      //date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); // 时区补偿
      this.form.ProDatetimeFrom = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showProDatetimeFrom = false;
    },
    onConfirmProDatetimeTo(time) {
      this.tempTime = time;
      //date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); // 时区补偿
      this.form.ProDatetimeTo = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showProDatetimeTo = false;
    },
    // 获取当前时间 yy-mm-dd hh:mf:ss
    getNowTimeToSecond() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      this.nowDate = dateTime;
      return dateTime;
    },
  },
  // 获取当前时间 yy-mm-dd
  getNowTime(date) {
    let yy = date.getFullYear();
    let mm = date.getMonth() + 1;
    let dd = date.getDate();
    return yy + "-" + mm + "-" + dd;
  },
};
</script>

<style>
body {
  background-color: white;
}
</style>
